<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="Admin_Users.aspx.cs" Inherits="Admin_Users" Title="Tackle - Administration of Users" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHolder" runat="Server">
    <strong>Administer Users<br />
        <br />
    </strong><span style="font-size: 8pt">This page allows the management of users for this
        web site.<br />
    </span>
    <br />
    <table width="98%" cellpadding="4" cellspacing="0">
        <tr>
            <td bgcolor="#e3eaeb" style="border-right: silver 1px ridge; border-top: silver 1px ridge;
                border-left: silver 1px ridge; border-bottom: silver 1px ridge">
                <span style="font-size: x-small">Page size:</span><strong> </strong>
                <asp:DropDownList ID="dlPageSize" runat="server" AutoPostBack="True" Font-Names="Verdana"
                    Font-Size="X-Small" OnSelectedIndexChanged="dlPageSize_SelectedIndexChanged">
                    <asp:ListItem>10</asp:ListItem>
                    <asp:ListItem>25</asp:ListItem>
                    <asp:ListItem>50</asp:ListItem>
                    <asp:ListItem>100</asp:ListItem>
                    <asp:ListItem>All</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td>
                <asp:GridView ID="gvUsers" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                    CellPadding="4" DataKeyNames="UserID" DataSourceID="dsAdminUsers" ForeColor="#333333"
                    GridLines="None" Font-Names="Verdana" Font-Size="X-Small" AllowPaging="True"
                    PageSize="15" OnPreRender="gvUsers_PreRender" OnRowDeleting="gvUsers_RowDeleting" OnRowUpdating="gvUsers_RowUpdating">
                    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <Columns>
                        <asp:BoundField DataField="UserID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                            SortExpression="UserID" Visible="False" />
                        <asp:TemplateField HeaderText="Name" SortExpression="UserName">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("UserName") %>' Font-Names="Verdana"
                                    Font-Size="X-Small" MaxLength="50" ToolTip="Enter the users Alias name. This is used for authentication of users."></asp:TextBox><asp:RequiredFieldValidator
                                        ID="rfv1" runat="server" ControlToValidate="TextBox1" ErrorMessage="*?" ForeColor="LightCoral"
                                        Font-Names="Verdana" Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Font-Names="Verdana" Font-Size="X-Small" Text='<%# Bind("UserName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Default Team" SortExpression="ScrumTeamName">
                            <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="dsScrumTeam" DataTextField="ScrumTeamName"
                                    DataValueField="ScrumTeamID" Font-Names="Verdana" Font-Size="X-Small" SelectedValue='<%# Bind("fDefaultScrumTeamID") %>'
                                    ToolTip="Select the default Scrum Team for this user. The scrum team will automatically be chosen when a user accesses the site.">
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("ScrumTeamName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Permissions">
                            <EditItemTemplate>
                                &nbsp;
                            </EditItemTemplate>
                            <ItemTemplate>
                                &nbsp;<asp:LinkButton ID="lnkUserPermisson" runat="server" CommandArgument='<%# Bind("UserID") %>'
                                    OnClick="lnkUserPermisson_Click" PostBackUrl="~/Admin_UserPermission.aspx" ForeColor="Black">Set</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False">
                            <EditItemTemplate>
                                <asp:LinkButton ID="lnkUpdateRecord" runat="server" CausesValidation="True" CommandName="Update"
                                    ForeColor="Black" Text="Update"></asp:LinkButton>
                                <asp:LinkButton ID="lnkCancelRecordEditing" runat="server" CausesValidation="False"
                                    CommandName="Cancel" ForeColor="Black" Text="Cancel"></asp:LinkButton>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkEditRecord" runat="server" CausesValidation="False" CommandArgument='<%# Bind("UserID") %>'
                                    CommandName="Edit" ForeColor="Black" OnClick="lnkEditRecord_Click" Text="Edit"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkDeleteRecord" runat="server" CausesValidation="False" CommandName="Delete"
                                    ForeColor="Black" OnClientClick="return confirm('Are you sure you want to delete this record?');"
                                    Text="Delete" ToolTip="Delete this record"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <RowStyle BackColor="#E3EAEB" />
                    <EditRowStyle BackColor="#7C6F57" />
                    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
        </tr>
        <tr>
            <td>
                <asp:Button ID="btnNewUser" runat="server" Font-Size="X-Small" OnClick="btnNewUser_Click"
                    Text="New User" Font-Names="Verdana" />
                <asp:Label ID="lblErrorNoScrumTeam" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                    ForeColor="Red" Text="At least one scrum team is required to create a new user."
                    Visible="False"></asp:Label></td>
        </tr>
    </table>
    <asp:SqlDataSource ID="dsAdminUsers" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
        SelectCommand="SELECT tblUsers.UserID, tblUsers.UserName, tblUsers.fDefaultScrumTeamID, tblScrumTeam.ScrumTeamName FROM tblUsers INNER JOIN tblScrumTeam ON tblUsers.fDefaultScrumTeamID = tblScrumTeam.ScrumTeamID&#13;&#10;ORDER BY UserName"
        DeleteCommand="DELETE tblUsers WHERE (UserID=@original_UserID)" OldValuesParameterFormatString="original_{0}"
        UpdateCommand="UPDATE tblUsers SET UserName = @UserName, fDefaultScrumTeamID = @fDefaultScrumTeamID WHERE (UserID = @original_UserID)">
        <UpdateParameters>
            <asp:Parameter Name="UserName" />
            <asp:Parameter Name="original_UserID" />
            <asp:Parameter Name="fDefaultScrumTeamID" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsScrumTeam" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
        SelectCommand="SELECT tblScrumTeam.ScrumTeamID, tblScrumTeam.ScrumTeamName FROM tblScrumTeam ORDER BY tblScrumTeam.ScrumTeamName">
    </asp:SqlDataSource>
</asp:Content>
